package com.momo.mal.dashboard;

import com.momo.mal.Login;
import net.momo.mal.R;
import com.momo.mal.database.MalDatabaseAdapter;
import com.momo.mal.util.ConnectionUtil;


import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.Toast;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;

public class StatisticFragment extends Fragment {
	private static final String KEY_CONTENT = "StatisticFragment:Content";
	private TextView animeDays, animeWatching, animeCompleted, animeOnHold, 
		animeDropped, animePlanToWatch, animeTotal;
	private TextView mangaDays, mangaReading, mangaCompleted, mangaOnHold,
		mangaDropped, mangaPlanToRead, mangaTotal;
	private JSONObject json;
	private MalDatabaseAdapter dbAdapter;

    public static StatisticFragment newInstance() {
    	StatisticFragment fragment = new StatisticFragment();
    	
        return fragment;
    }

    private String mContent = "???";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if ((savedInstanceState != null) && savedInstanceState.containsKey(KEY_CONTENT)) {
            mContent = savedInstanceState.getString(KEY_CONTENT);
        }
        
        dbAdapter = new MalDatabaseAdapter(getActivity());
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.dashboard_tab_statistic, null);
        
//        animeDays = (TextView) view.findViewById(R.id.text_anime_days);
		animeWatching = (TextView) view.findViewById(R.id.text_anime_watching);
		animeCompleted = (TextView) view.findViewById(R.id.text_anime_complete);
		animeOnHold = (TextView) view.findViewById(R.id.text_anime_on_hold);
		animeDropped = (TextView) view.findViewById(R.id.text_anime_dropped);
		animePlanToWatch = (TextView) view.findViewById(R.id.text_anime_plan_to_watch);
		animeTotal = (TextView) view.findViewById(R.id.text_anime_total);
		
//		mangaDays = (TextView) view.findViewById(R.id.text_manga_days);
		mangaReading = (TextView) view.findViewById(R.id.text_manga_reading);
		mangaCompleted = (TextView) view.findViewById(R.id.text_manga_complete);
		mangaOnHold = (TextView) view.findViewById(R.id.text_manga_on_hold);
		mangaDropped = (TextView) view.findViewById(R.id.text_manga_dropped);
		mangaPlanToRead = (TextView) view.findViewById(R.id.text_manga_plan_to_read);
		mangaTotal = (TextView) view.findViewById(R.id.text_manga_total);
		
//		animeDays.setText("Time (Days) : " + dbAdapter.getStatistic()[0]);
		animeWatching.setText("Watching : " + dbAdapter.countAnimeByStatus("watching"));
		animeCompleted.setText("Completed : " + dbAdapter.countAnimeByStatus("completed"));
		animeOnHold.setText("On Hold : " + dbAdapter.countAnimeByStatus("onhold"));
		animeDropped.setText("Dropped : " + dbAdapter.countAnimeByStatus("dropped"));
		animePlanToWatch.setText("Plan to Watch : " + dbAdapter.countAnimeByStatus("plantowatch"));
		animeTotal.setText("Total Entries : " + dbAdapter.countAnime());
			
//		mangaDays.setText("Time (Days) : " + dbAdapter.getStatistic()[1]);
		mangaReading.setText("Reading : " + dbAdapter.countMangaByStatus("reading"));
		mangaCompleted.setText("Completed : " + dbAdapter.countMangaByStatus("completed"));
		mangaOnHold.setText("On Hold : " + dbAdapter.countMangaByStatus("onhold"));
		mangaDropped.setText("Dropped : " + dbAdapter.countMangaByStatus("dropped"));
		mangaPlanToRead.setText("Plan to Read : " + dbAdapter.countMangaByStatus("plantoread"));
		mangaTotal.setText("Total Entries : " + dbAdapter.countManga());
		
        return view;
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putString(KEY_CONTENT, mContent);
    }
    
    
}
